package top.xiaoqy.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

/**
 * 元数据处理
 * 日期自动增删改查处理操作
 * 没有搜到怎么写
 *
 * @Author: 小清远
 * @Time: 2023/9/30 19:44
 */
@Repository
@Slf4j
public class MybatisPlusHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("Insert");
        //可能对  https://baomidou.com/pages/4c6bcf/
//        this.strictInsertFill(metaObject,"createTime",LocalDateTime.class,LocalDateTime.now());
        this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("updateTime",LocalDateTime.now(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("Update");
        this.setFieldValByName("updateTime",LocalDateTime.now(),metaObject);
    }
}
